package com.atguigu.vodObject;

import com.aliyun.vod.upload.impl.UploadVideoImpl;
import com.aliyun.vod.upload.req.UploadVideoRequest;
import com.aliyun.vod.upload.resp.UploadVideoResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.vod.model.v20170321.*;

import java.util.List;

public class testObject {

    public static void main(String[] args) throws ClientException {
        String accessKeyId = "LTAI4GDpN8mgh8YwJ8scejSq";
        String accessKeySecret = "DVBIxxNMSNdZ3DxWj0wTHMmUfYZtpN";
        String title = "3 - How Does Project Submission Work - upload by sdk";
        String fileName = "F:\\guli\\项目资料\\1-阿里云上传测试视频\\6 - What If I Want to Move Faster.mp4";
        UploadVideoRequest request = new UploadVideoRequest(accessKeyId, accessKeySecret, title, fileName);
        /* 可指定分片上传时每个分片的大小，默认为2M字节 */
        request.setPartSize(2 * 1024 * 1024L);
        request.setTaskNum(1);
        // request.setEcsRegionId("cn-shanghai");
        UploadVideoImpl uploader = new UploadVideoImpl();
        UploadVideoResponse response = uploader.uploadVideo(request);

        if (response.isSuccess()) {
            System.out.print("VideoId=" + response.getVideoId() + "\n");
        } else {
            /* 如果设置回调URL无效，不影响视频上传，可以返回VideoId同时会返回错误码。其他情况上传失败时，VideoId为空，此时需要根据返回错误码分析具体错误原因 */
            System.out.print("VideoId=" + response.getVideoId() + "\n");
            System.out.print("ErrorCode=" + response.getCode() + "\n");
            System.out.print("ErrorMessage=" + response.getMessage() + "\n");
        }
    }


    public static void getVideoAuto() throws ClientException {
        //根据视频id获取视频凭证
        DefaultAcsClient client = initObject.initVodClient("LTAI4GDpN8mgh8YwJ8scejSq", "DVBIxxNMSNdZ3DxWj0wTHMmUfYZtpN");

        GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
        GetVideoPlayAuthResponse response = new GetVideoPlayAuthResponse();

        request.setVideoId("1c866594f3334ee7aafbbb06ac2c7cba");
        response = client.getAcsResponse(request);

        System.out.println("playauto:" + response.getPlayAuth());
    }

    public static void getVideoUrl() throws ClientException {
        //根据视频id获取视频地址
        //创建初始化对象
        DefaultAcsClient initVodClient = initObject.initVodClient("LTAI4GDpN8mgh8YwJ8scejSq", "DVBIxxNMSNdZ3DxWj0wTHMmUfYZtpN");

        //创建获取地址request、response
        GetPlayInfoRequest request = new GetPlayInfoRequest();
        GetPlayInfoResponse response = new GetPlayInfoResponse();

        //向request对象里面设置视频id
        request.setVideoId("1c866594f3334ee7aafbbb06ac2c7cba");
        //调用初始化对象里面的方法，传递request，获取数据
        response = initVodClient.getAcsResponse(request);
        List<GetPlayInfoResponse.PlayInfo> playInfoList = response.getPlayInfoList();
        //播放地址
        for (GetPlayInfoResponse.PlayInfo playInfo : playInfoList) {
            System.out.print("PlayInfo.PlayURL = " + playInfo.getPlayURL() + "\n");
        }
        //Base信息
        System.out.print("VideoBase.Title = " + response.getVideoBase().getTitle() + "\n");
    }
}
